package com.syc.mybatis.dao;

import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.syc.mybatis.domain.Person;
import com.syc.mybatis.utils.MyBatisUtil;

public class PersonDao {

	public int dynamicUpdate(int id, String name, String nickname) {
		SqlSession session = MyBatisUtil.getSqlSession();

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pid", id);
		map.put("name", name);
		map.put("nickname", nickname);

		int lines = session.update(Person.class.getName() + ".dynamicUpdate", map);

		//在进行增删改的时候,必须提交事务,否则增删改操作无效!
		session.commit();

		MyBatisUtil.closeSqlSession();

		return lines;
	}
}
